cmake_minimum_required(VERSION 3.5)

project(smartpipe)

find_package(OpenCV REQUIRED PATHS /home/lx/ NO_DEFAULT_PATH)

set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -O3 -pthread")

set(CMAKE_EXE_LINKER_FLAGS "-lpthread")

include_directories(./include/
                    ./include/core/
                    ./include/apis/
                    ./include/tools/
                    ./include/core/functions/Image/Crop/
                    ./include/core/functions/Image/Gen/
                    ./include/core/functions/Image/Mark/
                    ./include/core/functions/Image/Pull/
                    ./include/core/functions/Image/Push/
                    ./include/core/functions/Image/Resize/
                    ./include/core/functions/Image/Save/
                    ./include/core/functions/Image/Trans/
                    ./include/core/functions/Model/Group/
                    ./include/core/functions/Model/Split/
                    ./include/core/functions/Model/Trans/
                    ./include/core/functions/Model/Yolo/
                    ./include/core/functions/Model/Openpose/
                    ./include/core/functions/Model/Retinanet/
                    ./include/core/functions/Model/LPRnet/
                    ./include/core/functions/Tool/Group/
                    ./include/core/functions/Tool/Split/
                    /data/lx/anaconda3/include/freetype2/
                    /home/lx/.conda/envs/smartpipe/include/python3.8/
                    /data/lx/.local/lib/python3.8/site-packages/numpy/core/include/
                    /home/lx/pytorch/c10/cuda/
                    ${OpenCV_INCLUDE_DIRS})

# 生成静态链接库
add_library(smartpipe
            # core framework
            ./src/core/function.cpp 
            ./src/core/executor.cpp 
            ./src/core/profile.cpp 
            ./src/core/util.cpp 
            ./src/core/data.cpp
            ./src/core/memory.cpp 
            ./src/core/app.cpp 
            ./src/tools/mdReader.cpp
            ./src/tools/CvxText.cpp
            # functions
            ./src/core/functions/Image/Gen/genFromDisk.cpp
            ./src/core/functions/Image/Gen/genFromMemory.cpp
            ./src/core/functions/Image/Mark/markWithString.cpp
            ./src/core/functions/Image/Pull/pullFromRtsp.cpp
            ./src/core/functions/Image/Push/pushWithRtsp.cpp
            ./src/core/functions/Image/Push/pushWithRtmp.cpp
            ./src/core/functions/Image/Resize/resize.cpp
            ./src/core/functions/Image/Resize/letterBoxResize.cpp
            ./src/core/functions/Image/Save/markAndSave.cpp
            ./src/core/functions/Image/Save/save.cpp
            ./src/core/functions/Image/Trans/trans.cpp
            ./src/core/functions/Image/Crop/cropWithInput.cpp
            ./src/core/functions/Image/Crop/cropWithParas.cpp
            ./src/core/functions/Model/LPRnet/lprnet_postprocess.cpp
            ./src/core/functions/Model/LPRnet/lprnet_inference.cpp
            ./src/core/functions/Model/LPRnet/lprnet_preprocess.cpp
            ./src/core/functions/Model/Openpose/openpose_preprocess.cpp
            ./src/core/functions/Model/Openpose/openpose_inference.cpp
            ./src/core/functions/Model/Openpose/openpose_postprocess.cpp
            ./src/core/functions/Model/Group/groupByBatch.cpp
            ./src/core/functions/Model/Retinanet/retinanet_preprocess.cpp
            ./src/core/functions/Model/Retinanet/retinanet_postprocess.cpp
            ./src/core/functions/Model/Retinanet/retinanet_inference.cpp
            ./src/core/functions/Model/Split/splitByShape.cpp
            ./src/core/functions/Model/Trans/transferToDeviceMemory.cpp
            ./src/core/functions/Model/Trans/transferToHostMemory.cpp
            ./src/core/functions/Model/Yolo/yolo_complete.cpp
            ./src/core/functions/Model/Yolo/yolo_preprocess.cpp
            ./src/core/functions/Model/Yolo/yolo_postprocess.cpp
            ./src/core/functions/Model/Yolo/yolo_inference.cpp
            ./src/core/functions/Tool/Group/groupByRequestId.cpp
            ./src/core/functions/Tool/Split/splitByFlowId.cpp
            # apis
            ./src/apis/smartpipe.cpp)

# 生成动态链接库
add_library(smartpipe_shared SHARED
            # core framework
            ./src/core/function.cpp 
            ./src/core/executor.cpp 
            ./src/core/profile.cpp 
            ./src/core/util.cpp 
            ./src/core/data.cpp
            ./src/core/memory.cpp 
            ./src/core/app.cpp 
            ./src/tools/mdReader.cpp
            ./src/tools/CvxText.cpp
            # functions
            ./src/core/functions/Image/Gen/genFromDisk.cpp
            ./src/core/functions/Image/Gen/genFromMemory.cpp
            ./src/core/functions/Image/Resize/resize.cpp
            ./src/core/functions/Image/Resize/letterBoxResize.cpp
            ./src/core/functions/Image/Save/markAndSave.cpp
            ./src/core/functions/Image/Save/save.cpp
            ./src/core/functions/Image/Trans/trans.cpp
            ./src/core/functions/Image/Crop/cropWithInput.cpp
            ./src/core/functions/Image/Crop/cropWithParas.cpp
            ./src/core/functions/Model/LPRnet/lprnet_postprocess.cpp
            ./src/core/functions/Model/LPRnet/lprnet_inference.cpp
            ./src/core/functions/Model/LPRnet/lprnet_preprocess.cpp
            ./src/core/functions/Model/Openpose/openpose_preprocess.cpp
            ./src/core/functions/Model/Openpose/openpose_inference.cpp
            ./src/core/functions/Model/Openpose/openpose_postprocess.cpp
            ./src/core/functions/Model/Group/groupByBatch.cpp
            ./src/core/functions/Model/Retinanet/retinanet_preprocess.cpp
            ./src/core/functions/Model/Retinanet/retinanet_postprocess.cpp
            ./src/core/functions/Model/Retinanet/retinanet_inference.cpp
            ./src/core/functions/Model/Split/splitByShape.cpp
            ./src/core/functions/Model/Trans/transferToDeviceMemory.cpp
            ./src/core/functions/Model/Trans/transferToHostMemory.cpp
            ./src/core/functions/Model/Yolo/yolo_complete.cpp
            ./src/core/functions/Model/Yolo/yolo_preprocess.cpp
            ./src/core/functions/Model/Yolo/yolo_postprocess.cpp
            ./src/core/functions/Model/Yolo/yolo_inference.cpp
            ./src/core/functions/Tool/Group/groupByRequestId.cpp
            ./src/core/functions/Tool/Split/splitByFlowId.cpp
            # apis
            ./src/apis/smartpipe.cpp)

# 生成可执行文件
add_executable(main 
            ./src/main.cpp)

# 可执行文件链接库
target_link_libraries(main
                    smartpipe
                    freetype
                    ${OpenCV_LIBS}
                    /home/lx/.conda/envs/smartpipe/lib/libpython3.8.so)

# 设置编译模式
set(CMAKE_BUILD_TYPE "Release")

# 安装库和可执行文件到指定位置
install(TARGETS smartpipe smartpipe_shared LIBRARY DESTINATION /home/lx/SmartPipe/build/lib)